package com.sumainfor.pc.gmio.service.impl;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.pc.gmio.dao.DiChargesDeptMapper;
import com.sumainfor.pc.gmio.service.DiChargesDeptService;
import com.sumainfor.pc.gmio.service.DiHousingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 查询市场部房源列表
 */
@Service
public class DiChargesDeptSerivceImpl implements DiChargesDeptService {

    private ReentrantLock lock = new ReentrantLock(false);
    Logger log = LoggerFactory.getLogger(DiChargesDeptSerivceImpl.class);
    @Autowired
    private DiChargesDeptMapper diChargesDeptMapper;
    /*
     * 查询各个地区的水电燃收费标准(租赁顾问签约、运营助理工作台发钥匙)
     * */
    public Map<String,Object> getChargesDept(Map<String, Object> params){
        List<String> ContactIdList=new ArrayList<String>();
        if(params.get("areaId")!=null){
            ContactIdList.add(params.get("areaId").toString());
        }if(params.get("HouId")!=null){
            ContactIdList.add(params.get("HouId").toString());
        }if(params.get("CorId")!=null){
            ContactIdList.add(params.get("CorId").toString());
        }if(params.get("ComId")!=null){
            ContactIdList.add(params.get("ComId").toString());
        }if(params.get("MiId")!=null){
            ContactIdList.add(params.get("MiId").toString());
        }if(params.get("HouInfoId")!=null){
            ContactIdList.add(params.get("HouInfoId").toString());
        }

        params.put("ContactIdList",ContactIdList);
        //根据收费标准关联的5个编号排序查询出一条
        Map<String,Object> map=diChargesDeptMapper.getChargesDept(params);
        if (map!=null){
            int wCount=0;// 0 水费标准正常 1水费标准异常（不能即有定价又有定额）
            if (map.get("WaterPricing")==null || map.get("WaterPricings")==null){
                if(map.get("WaterPricing")==null && map.get("WaterPricings")==null){
                    wCount=1;
                }else{
//
//                    if (map.get("WaterPricing").toString().equals("") && map.get("WaterPricings").toString().equals("")){
//                        wCount=1;
//                    }
//                    else{
//                        wCount=0;
//                        if (map.get("WaterPricing").toString().equals("") || map.get("WaterPricing")==null){//0定额 1定价
//                            map.put("isWater",0);
//                        }else{
//                            map.put("isWater",1);
//                        }
//                    }

                    wCount=0;
                    if (map.get("WaterPricing")==null){//0定额 1定价
                            map.put("isWater",0);
                        }else{
                            map.put("isWater",1);
                        }


                }
            }else{
                wCount=1;
            }
            int gCount=0;// 0 燃气费标准正常 1燃气费标准异常（不能即有定价又有定额）
            if (map.get("GasPricing")==null || map.get("GasPricings")==null){
                if(map.get("GasPricing")==null && map.get("GasPricings")==null){
                    gCount=1;
                }else{
//                    if (map.get("GasPricing").toString().equals("") && map.get("GasPricings").toString().equals("")){
//                        gCount=1;
//                    }
//                    else{
//                        gCount=0;
//                        if (map.get("GasPricing").toString().equals("") ||  map.get("GasPricing")==null ){//0定额 1定价
//                            map.put("isGas",0);
//                        }else{
//                            map.put("isGas",1);
//                        }
//                    }
                    gCount=0;
                    if ( map.get("GasPricing")==null ){//0定额 1定价
                        map.put("isGas",0);
                    }else{
                        map.put("isGas",1);
                    }
                }
            }else{
                gCount=1;
            }
            map.put("wCount",wCount);
            map.put("gCount",gCount);
        }else{
            map=new HashMap<String,Object>();
        }
        return map;
    }
    /*
     * 查询各个地区的水电燃收费标准 维修租客端
     * */
    public Map<String,Object> getChargesDeptWx(Map<String, Object> params){
        List<String> ContactIdList=new ArrayList<String>();
        if(params.get("areaId")!=null){
            ContactIdList.add(params.get("areaId").toString());
        }if(params.get("HouId")!=null){
            ContactIdList.add(params.get("HouId").toString());
        }if(params.get("CorId")!=null){
            ContactIdList.add(params.get("CorId").toString());
        }if(params.get("ComId")!=null){
            ContactIdList.add(params.get("ComId").toString());
        }if(params.get("MiId")!=null){
            ContactIdList.add(params.get("MiId").toString());
        }if(params.get("HouInfoId")!=null){
            ContactIdList.add(params.get("HouInfoId").toString());
        }
        params.put("ContactIdList",ContactIdList);
        //根据收费标准关联的5个编号排序查询出一条
        Map<String,Object> map=diChargesDeptMapper.getChargesDept(params);
        if (map!=null){
            int wCount=0;// 0 水费标准正常 1水费标准异常（不能即有定价又有定额）
            if (map.get("WaterPricing")==null || map.get("WaterPricings")==null){
                if(map.get("WaterPricing")==null && map.get("WaterPricings")==null){
                    wCount=1;
                }else{
                    if (map.get("WaterPricing").toString().equals("") && map.get("WaterPricings").toString().equals("")){
                        wCount=1;
                    }
                    else{
                        wCount=0;
                        if (map.get("WaterPricing").toString().equals("") || map.get("WaterPricing")==null){//0定额 1定价
                            map.put("isWater",0);
                        }else{
                            map.put("isWater",1);
                        }
                    }
                }
            }else{
                wCount=1;
            }
            int gCount=0;// 0 燃气费标准正常 1燃气费标准异常（不能即有定价又有定额）
            if (map.get("GasPricing")==null || map.get("GasPricings")==null){
                if(map.get("GasPricing")==null && map.get("GasPricings")==null){
                    gCount=1;
                }else{
                    if (map.get("GasPricing").toString().equals("") && map.get("GasPricings").toString().equals("")){
                        gCount=1;
                    }
                    else{
                        gCount=0;
                        if (map.get("GasPricing").toString().equals("") ||  map.get("GasPricing")==null ){//0定额 1定价
                            map.put("isGas",0);
                        }else{
                            map.put("isGas",1);
                        }
                    }
                }
            }else{
                gCount=1;
            }
            map.put("wCount",wCount);
            map.put("gCount",gCount);
        }else{
            map=new HashMap<String,Object>();
        }
        return map;
    }
    /**
     *租客端统计智能电表余额查询房源的收费标准
     */
    public JsonResult getRdChargesDeptList(Map<String,Object> params){
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list=diChargesDeptMapper.getChargesDeptList(params);
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return result;
    }


}
